package com.wuchao.util;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @Author wuchao66
 * @Date 2023/8/25 16:13
 * @PackageName:com.wuchao.utils
 * @ClassName: Interceptors
 * @Description: TODO
 * @Param
 * @Version 1.0
 */
public class SysInterceptor extends HandlerInterceptorAdapter
{
    //白名单---游客都能看 论坛 新闻资讯和黑名单--抽奖
    public boolean preHandle(
            HttpServletRequest request
            , HttpServletResponse response,
            Object handler) throws Exception {//
        System.out.println("进入自定义拦截器==>SysInterceptor");
        HttpSession session = request.getSession();//***************
        Object user = session.getAttribute("user");//做常量
        if(user==null||user==""){
            System.out.println("被拦截");
            response.sendRedirect(request.getContextPath()+"/index.jsp");
            return false;
        } System.out.println("无效拦截");
        return true;
    }
}
